package com.os.opencv.java.chapter7;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class MorphologyEx1 {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/bubble.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);
        Mat dst = new Mat();

        //闭运算1次并在屏幕上显示
        Point anchor = new Point(-1,-1);
        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, new Mat(), anchor, 1);
        HighGui.imshow("close-1", dst);
        HighGui.waitKey(0);

        //闭运算3次并在屏幕上显示
        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, new Mat(), anchor, 3);
        HighGui.imshow("close-3", dst);
        HighGui.waitKey(0);

        //在3次闭运算的基础上进行开运算并在屏幕上显示
        Imgproc.morphologyEx(dst, dst, Imgproc.MORPH_OPEN, new Mat(), anchor, 1);
        HighGui.imshow("open", dst);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
